package liwen.zhao.controller;

import liwen.zhao.common.jd.pojo.Article;
import liwen.zhao.common.jd.vo.SysResult;
import liwen.zhao.service.ElasticsearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@Controller
@RestController
@RequestMapping("/es")
public class ElasticsearchController {
    @Autowired
    private ElasticsearchService elasticsearchService;
    @RequestMapping("/createIndex")
    public SysResult createIndex(String indexName,String type){
        return elasticsearchService.createIndexByNameAndType(indexName,type);
    }
    
    @RequestMapping("/search")
    public  List<Article> search(String text, Integer page, Integer rows){
        try {
            return  elasticsearchService.search(text, page, rows);
        } catch (IOException e) {
            e.printStackTrace();
            return  null;
        }
    }
}
